package net.lym.es.index;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * ES 测试 ：索引-删除
 */
public class ESTest_Index_Delete {
    public static void main(String[] args) throws Exception {

        // 创建 ES 客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http"))
        );

        // 删除索引 - 请求对象
        DeleteIndexRequest request = new DeleteIndexRequest("user");

        // 发送请求，获取响应
        AcknowledgedResponse response = esClient.indices().delete(request, RequestOptions.DEFAULT);

        // 响应状态
        System.out.println("操作结果 ：" + response.isAcknowledged());

        // 关闭 ES 客户端
        esClient.close();
    }
}
